/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * addEditDatabaseDialog.java
 *
 * Created on Jul 13, 2011, 11:59:00 AM
 */

package cnsatmsmart.automation.mmi.view.dialogs;

import cnsatmsmart.automation.mmi.helper.utilities.GlobalEnvVars;
import cnsatmsmart.automation.mmi.model.database.DataBase;
import cnsatmsmart.automation.mmi.model.data.component.JTextFieldFilter;
import java.awt.Image;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 *
 * @author SIK - PTIK, BPPT
 */
public class addEditDatabaseDialog extends javax.swing.JDialog {

    /* atribut - atribut yang dimiliki oleh kelas addEditDatabaseDialog */
        private DataBase db;                    //database yang akan dibuat connection-nya
        private int table_id;                   //id tabel yang akan diedit atau ditambahkan
        private String ID;                      //ID yang akan diedit
        private boolean isEdit;                 //true jika edit dan false jika add
        private databaseSettings dbset;         //databaseSetting untuk meng-update tampilan tabel
        private DefaultListModel listModel;     //model list untuk menambah dan mengurangi element

    /** Constructor - user defined constructor, no default constructor <br />
     * membuat form baru addEditDatabaseDialog <br />
     * form yang tampil tergantung pada tabel dan aksi yang dipilih sebelumnya
     * @param parent - parent untuk parameter constructor JDialog
     * @param dbset - object databaseSettings
     * @param modal - modal untuk parameter constructor JDialog
     * @param db - database
     * @param table_id - id tabel yang akan diedit atau ditambahkan
     * @param ID - ID jika dipilih edit
     * @param panels - true untuk Panel1 dan false untuk Panel2
     * @param isEdit - true jika akan mengedit database yang sudah ada dan false jika menambahkan database
     */
        public addEditDatabaseDialog(java.awt.Frame parent, boolean modal, databaseSettings dbset, DataBase db, int table_id, String ID, boolean panels, boolean isEdit) {
            super(parent, modal);
            initComponents();

            Image frameIcon = GlobalEnvVars.kit.getImage(getClass().getResource("/cnsatmsmart/resources/"+GlobalEnvVars.icon));
            setIconImage(frameIcon);
            setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
            setAlwaysOnTop(true);
            setResizable(false);
            setLocationRelativeTo(null);

            this.dbset = dbset;
            this.db = db;
            this.table_id = table_id;
            this.ID = ID;
            this.isEdit = isEdit;

            if (panels)
            {
                Panel2.setVisible(false);
                Panel1.setVisible(true);
                this.getContentPane().add(Panel1);

                txtID.setText("");
                txtID.setColumns(10);
                txtID.setDocument(new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC));
                txtLatDeg.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC));
                txtLatMin.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC));
                txtLatSec.setDocument(new JTextFieldFilter(JTextFieldFilter.FLOAT));
                txtLonDeg.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC));
                txtLonMin.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC));
                txtLonSec.setDocument(new JTextFieldFilter(JTextFieldFilter.FLOAT));
            }
            else
            {
                Panel2.setVisible(true);
                Panel1.setVisible(false);
                pathList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
                this.getContentPane().add(Panel2);
                listModel = new DefaultListModel();
                pathList.setModel(listModel);
                txtID1.setText("");
                txtID1.setColumns(10);
                txtID1.setDocument(new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC));
            }

            initProperty(panels);
        }

    /* method - method lain yang dimiliki oleh kelas addEditDatabaseDialog */
        /**
         * mengedit komponen-komponen yang ada pada Panel1 atau Panel2
         * @param panels true untuk mengedit komponen-komponen Panel1 dan false untuk mengedit komponen-komponen Panel2
         */
        private void initProperty(boolean panels)
        {
            if (panels)
            {
                switch (this.table_id)
                {
                    case databaseSettings.AIRPORTS:
                    {
                        labelID.setText("ID Airport :");
                        if (isEdit)
                        {
                            setTitle("Edit Database Airports Table");
                            txtID.setText(this.ID);
                            txtID.setEditable(false);
                            try {
                                db.createQuery("SELECT * FROM airports WHERE ID_Airports = '" + this.ID + "';");
                                while (db.getResultSet().next()) {
                                    txtLatDeg.setText(db.getResultSet().getString("Lat_Deg"));
                                    txtLatMin.setText(db.getResultSet().getString("Lat_Min"));
                                    txtLatSec.setText(db.getResultSet().getString("Lat_Sec"));
                                    spinLatitude.setSelectedItem(db.getResultSet().getString("Lat_Sign"));
                                    txtLonDeg.setText(db.getResultSet().getString("Lon_Deg"));
                                    txtLonMin.setText(db.getResultSet().getString("Lon_Min"));
                                    txtLonSec.setText(db.getResultSet().getString("Lon_Sec"));
                                    spinLongitude.setSelectedItem(db.getResultSet().getString("Lon_Sign"));
                                }
                            } catch (SQLException ex) {
                                Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        else
                        {
                            setTitle("Add Database Airports Table");
                            txtLatDeg.setText("0");
                            txtLatMin.setText("0");
                            txtLatSec.setText("0.0");
                            spinLatitude.setSelectedItem("N");
                            txtLonDeg.setText("0");
                            txtLonMin.setText("0");
                            txtLonSec.setText("0.0");
                            spinLongitude.setSelectedItem("W");
                        }
                        break;
                    }
                    case databaseSettings.FIXES:
                    {
                        labelID.setText("ID Fix :");
                        if (isEdit)
                        {
                            setTitle("Edit Database Fixes Table");
                            txtID.setText(this.ID);
                            txtID.setEditable(false);
                            try {
                                db.createQuery("SELECT * FROM fixes WHERE ID_Fixes = '" + this.ID + "';");
                                while (db.getResultSet().next()) {
                                    txtLatDeg.setText(db.getResultSet().getString("Lat_Deg"));
                                    txtLatMin.setText(db.getResultSet().getString("Lat_Min"));
                                    txtLatSec.setText(db.getResultSet().getString("Lat_Sec"));
                                    spinLatitude.setSelectedItem(db.getResultSet().getString("Lat_Sign"));
                                    txtLonDeg.setText(db.getResultSet().getString("Lon_Deg"));
                                    txtLonMin.setText(db.getResultSet().getString("Lon_Min"));
                                    txtLonSec.setText(db.getResultSet().getString("Lon_Sec"));
                                    spinLongitude.setSelectedItem(db.getResultSet().getString("Lon_Sign"));
                                }
                            } catch (SQLException ex) {
                                Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        else
                        {
                            setTitle("Add Database Fixes Table");
                            txtLatDeg.setText("0");
                            txtLatMin.setText("0");
                            txtLatSec.setText("0.0");
                            spinLatitude.setSelectedItem("N");
                            txtLonDeg.setText("0");
                            txtLonMin.setText("0");
                            txtLonSec.setText("0.0");
                            spinLongitude.setSelectedItem("W");
                        }
                        break;
                    }
                    case databaseSettings.NAVAIDS:
                    {
                        labelID.setText("ID Navaid :");
                        if (isEdit)
                        {
                            setTitle("Edit Database Navaids Table");
                            txtID.setText(this.ID);
                            txtID.setEditable(false);
                            try {
                                db.createQuery("SELECT * FROM navaids WHERE ID_Navaids = '" + this.ID + "';");
                                while (db.getResultSet().next()) {
                                    txtLatDeg.setText(db.getResultSet().getString("Lat_Deg"));
                                    txtLatMin.setText(db.getResultSet().getString("Lat_Min"));
                                    txtLatSec.setText(db.getResultSet().getString("Lat_Sec"));
                                    spinLatitude.setSelectedItem(db.getResultSet().getString("Lat_Sign"));
                                    txtLonDeg.setText(db.getResultSet().getString("Lon_Deg"));
                                    txtLonMin.setText(db.getResultSet().getString("Lon_Min"));
                                    txtLonSec.setText(db.getResultSet().getString("Lon_Sec"));
                                    spinLongitude.setSelectedItem(db.getResultSet().getString("Lon_Sign"));
                                }
                            } catch (SQLException ex) {
                                Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        else
                        {
                            setTitle("Add Database Navaids Table");
                            txtLatDeg.setText("0");
                            txtLatMin.setText("0");
                            txtLatSec.setText("0.0");
                            spinLatitude.setSelectedItem("N");
                            txtLonDeg.setText("0");
                            txtLonMin.setText("0");
                            txtLonSec.setText("0.0");
                            spinLongitude.setSelectedItem("W");
                        }
                        break;
                    }
                    default:
                        break;
                }
            }
            else
            {
                Panel2.setVisible(true);
                Panel1.setVisible(false);
                this.getContentPane().add(Panel2);

                try {
                    java.util.List < String > allFix = new java.util.ArrayList < String > ();

                    db.createQuery("SELECT * FROM airports");
                    while (db.getResultSet().next()) {
                         allFix.add(db.getResultSet().getString("ID_Airports"));
                    }

                    db.createQuery("SELECT * FROM fixes");
                    while (db.getResultSet().next()) {
                         allFix.add(db.getResultSet().getString("ID_Fixes"));
                    }

                    db.createQuery("SELECT * FROM navaids");
                    while (db.getResultSet().next()) {
                         allFix.add(db.getResultSet().getString("ID_Navaids"));
                    }

                    for (String fix : allFix)
                    {
                        pathChoice.addItem(fix);
                    }
                } catch (SQLException ex) {
                    System.out.println("failed fetch from table airports, fixes, and navaids");
                }

                switch (this.table_id)
                {
                    case databaseSettings.AIRWAYS:
                    {
                        labelID1.setText("ID Airways :");
                        if (isEdit)
                        {
                            setTitle("Edit Database Airways Table");
                            txtID1.setText(this.ID);
                            txtID1.setEditable(false);
                            try {
                                db.createQuery("SELECT * FROM airways WHERE ID_Airways = '" + this.ID + "';");
                                String[] path_airways = {};
                                while (db.getResultSet().next()) {
                                    path_airways = (db.getResultSet().getString("Path_Airways")).split(";");
                                }
                                for (String str : path_airways)
                                {
                                    listModel.addElement(str);
                                    pathChoice.removeItem(str);
                                }
                            } catch (SQLException ex) {
                                Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        else
                        {
                            setTitle("Add Database Airways Table");
                        }
                        break;
                    }
                    case databaseSettings.FLIGHT_PLAN:
                    {
                        labelID1.setText("ID Flight :");
                        if (isEdit)
                        {
                            setTitle("Edit Database FlightPlan Table");
                            txtID1.setText(this.ID);
                            txtID1.setEditable(false);
                            try {
                                db.createQuery("SELECT * FROM flightplan WHERE ID_Flight = '" + this.ID + "';");
                                String[] path_flightplan = {};
                                while (db.getResultSet().next()) {
                                    path_flightplan = (db.getResultSet().getString("Path_FlightPlan")).split(";");
                                }
                                for (String str : path_flightplan)
                                {
                                    listModel.addElement(str);
                                    pathChoice.removeItem(str);
                                }
                            } catch (SQLException ex) {
                                Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        else
                        {
                            setTitle("Add Database FlightPlan Table");
                        }
                        break;
                    }
                }
            }
        }

        private Vector<String> validateInput()
        {
            Vector<String> listError = new Vector<String>();

            if (Panel1.isVisible())
            {
                if (!isEdit)
                {
                    //validate ID
                    if (txtID.getText().isEmpty())
                        listError.add("ID field is empty");
                    else
                        switch(this.table_id)
                        {
                            case databaseSettings.AIRPORTS:
                            {
                                if (txtID.getText().length() > 4)
                                    listError.add("ID too long");
                                    
                                db.createQuery("SELECT ID_Airports FROM airports;");
                                try {
                                    while (db.getResultSet().next()) {
                                        if (txtID.getText().equals(db.getResultSet().getString("ID_Airports")))
                                            listError.add("ID existing");
                                    }
                                } catch (SQLException ex) {
                                    Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                break;
                            }
                            case databaseSettings.FIXES:
                            {
                                if (txtID.getText().length() > 5)
                                    listError.add("ID too long");

                                db.createQuery("SELECT ID_Fixes FROM fixes;");
                                try {
                                    while (db.getResultSet().next()) {
                                        if (txtID.getText().equals(db.getResultSet().getString("ID_Fixes")))
                                            listError.add("ID existing");
                                    }
                                } catch (SQLException ex) {
                                    Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                break;
                            }
                            case databaseSettings.NAVAIDS:
                            {
                                if (txtID.getText().length() > 3)
                                    listError.add("ID too long");

                                db.createQuery("SELECT ID_Navaids FROM navaids;");
                                try {
                                    while (db.getResultSet().next()) {
                                        if (txtID.getText().equals(db.getResultSet().getString("ID_Navaids")))
                                            listError.add("ID existing");
                                    }
                                } catch (SQLException ex) {
                                    Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                break;
                            }
                            default:
                                break;
                        }
                }

                //validate Latitude
                String strDeg = txtLatDeg.getText();
                String strMin = txtLatMin.getText();
                String strSec = txtLatSec.getText();

                if (strDeg.isEmpty()) {
                    listError.add("Latitude degree field is empty");
                }
                if (strMin.isEmpty()) {
                    listError.add("Latitude minute field is empty");
                }
                if (strSec.isEmpty()) {
                    listError.add("Latitude second field is empty");
                }

                if (!strDeg.isEmpty() && !strMin.isEmpty() && !strDeg.isEmpty())
                {
                    int latDeg = Integer.parseInt(strDeg);
                    int latMin = Integer.parseInt(strMin);
                    Float latSec = Float.parseFloat(strSec);

                    if (latDeg > 90)
                        listError.add("Latitude degree value must be between 0-90");
                    if (latMin > 59)
                        listError.add("Latitude minute value must be between 0-59");
                    if (latSec > 3600.0f)
                        listError.add("Latitude second value must be between less than 3600");

                    float radarLatitude = (latDeg + (latMin / 60.0f) + (latSec / 3600.0f));
                    if (radarLatitude > 90.0f)
                    {
                        listError.add("Latitude value must be between 0-90");
                    }
                }

                //validate Longitude
                strDeg = txtLonDeg.getText();
                strMin = txtLonMin.getText();
                strSec = txtLonSec.getText();

                if (strDeg.isEmpty()) {
                    listError.add("Longitude degree field is empty");
                }
                if (strMin.isEmpty()) {
                    listError.add("Longitude minute field is empty");
                }
                if (strSec.isEmpty()) {
                    listError.add("Longitude second field is empty");
                }

                if (!strDeg.isEmpty() && !strMin.isEmpty() && !strDeg.isEmpty())
                {
                    int lonDeg = Integer.parseInt(strDeg);
                    int lonMin = Integer.parseInt(strMin);
                    float lonSec = Float.parseFloat(strSec);

                    if (lonDeg > 180)
                        listError.add("Latitude degree value must be between 0-180");
                    if (lonMin > 59)
                        listError.add("Latitude minute value must be between 0-59");
                    if (lonSec > 3600.0f)
                        listError.add("Latitude second value must be between less than 3600");

                    float radarLongitude = (lonDeg + (lonMin / 60.0f) + (lonSec / 3600.0f));
                    if (radarLongitude > 180.0f)
                    {
                        listError.add("Longitude value must be between 0-180");
                    }
                }
            }
            else
            {
                if (!this.isEdit)
                {
                    if (txtID1.getText().isEmpty())
                        listError.add("ID field is empty");
                    else
                        switch(this.table_id)
                        {
                            case databaseSettings.AIRWAYS:
                            {
                                if (txtID1.getText().length() > 4)
                                    listError.add("ID too long");

                                db.createQuery("SELECT ID_Airways FROM airways;");
                                try {
                                    while (db.getResultSet().next()) {
                                        if (txtID1.getText().equals(db.getResultSet().getString("ID_Airways")))
                                            listError.add("ID existing");
                                    }
                                } catch (SQLException ex) {
                                    Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                break;
                            }
                            case databaseSettings.FLIGHT_PLAN:
                            {
                                if (txtID1.getText().length() > 8)
                                    listError.add("ID too long");

                                db.createQuery("SELECT ID_Flight FROM flightplan;");
                                try {
                                    while (db.getResultSet().next()) {
                                        if (txtID1.getText().equals(db.getResultSet().getString("ID_Flight")))
                                            listError.add("ID existing");
                                    }
                                } catch (SQLException ex) {
                                    Logger.getLogger(addEditDatabaseDialog.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                break;
                            }
                            default:
                                break;
                        }
                }

                if (pathList.getModel().getSize() < 2)
                    listError.add("Path minimum two point");
            }

            return listError;
        }

        /**
         * mengambil isi dari setiap komponen yang ada dan mengisikan pada sebuah array String
         * @return String[] - isi dari komponen diubah menjadi array of String
         */
        private String[] getIsi()
        {
            if (Panel1.isVisible())
            {
                String lat_sign = (String)spinLatitude.getItemAt(spinLatitude.getSelectedIndex());
                String lon_sign = (String)spinLongitude.getItemAt(spinLongitude.getSelectedIndex());
                int latDeg = Integer.parseInt(txtLatDeg.getText());
                int latMin = Integer.parseInt(txtLatMin.getText());
                float latSec = Float.parseFloat(txtLatSec.getText());
                int lonDeg = Integer.parseInt(txtLonDeg.getText());
                int lonMin = Integer.parseInt(txtLonMin.getText());
                float lonSec = Float.parseFloat(txtLonSec.getText());

                String[] isi = {txtID.getText(),
                                latDeg + "",
                                latMin + "",
                                latSec + "",
                                lat_sign,
                                lonDeg + "",
                                lonMin + "",
                                lonSec + "",
                                lon_sign};
                return isi;
            }
            else
            {
                String path = "";
                for (int i = 0; i < pathList.getModel().getSize(); ++i)
                {
                    path += pathList.getModel().getElementAt(i) + ";";
                }

                String[] isi = {txtID1.getText(), path.substring(0,path.length()-1)};

                return isi;
            }
        }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Panel2 = new javax.swing.JPanel();
        labelID1 = new javax.swing.JLabel();
        txtID1 = new javax.swing.JTextField();
        btnSavePanel2 = new javax.swing.JButton();
        btnCancelPanel2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        pathList = new javax.swing.JList();
        pathChoice = new javax.swing.JComboBox();
        labelPath = new javax.swing.JLabel();
        btnRemove = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        Panel1 = new javax.swing.JPanel();
        labelID = new javax.swing.JLabel();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        txtLonDeg = new javax.swing.JTextField();
        txtLatDeg = new javax.swing.JTextField();
        txtLatMin = new javax.swing.JTextField();
        txtLonMin = new javax.swing.JTextField();
        txtLonSec = new javax.swing.JTextField();
        txtLatSec = new javax.swing.JTextField();
        spinLatitude = new javax.swing.JComboBox();
        spinLongitude = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
        btnSavePanel1 = new javax.swing.JButton();
        btnCancelPanel1 = new javax.swing.JButton();
        txtID = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        Panel2.setName("Panel2"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cnsatmsmart.CNSATMSMARTApp.class).getContext().getResourceMap(addEditDatabaseDialog.class);
        labelID1.setText(resourceMap.getString("labelID1.text")); // NOI18N
        labelID1.setName("labelID1"); // NOI18N

        txtID1.setText(resourceMap.getString("txtID1.text")); // NOI18N
        txtID1.setName("txtID1"); // NOI18N

        btnSavePanel2.setText(resourceMap.getString("btnSavePanel2.text")); // NOI18N
        btnSavePanel2.setName("btnSavePanel2"); // NOI18N
        btnSavePanel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSavePanel2ActionPerformed(evt);
            }
        });

        btnCancelPanel2.setText(resourceMap.getString("btnCancelPanel2.text")); // NOI18N
        btnCancelPanel2.setName("btnCancelPanel2"); // NOI18N
        btnCancelPanel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelPanel2ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        pathList.setName("pathList"); // NOI18N
        jScrollPane1.setViewportView(pathList);

        pathChoice.setName("pathChoice"); // NOI18N

        labelPath.setText(resourceMap.getString("labelPath.text")); // NOI18N
        labelPath.setName("labelPath"); // NOI18N

        btnRemove.setText(resourceMap.getString("btnRemove.text")); // NOI18N
        btnRemove.setName("btnRemove"); // NOI18N
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });

        btnAdd.setText(resourceMap.getString("btnAdd.text")); // NOI18N
        btnAdd.setName("btnAdd"); // NOI18N
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout Panel2Layout = new javax.swing.GroupLayout(Panel2);
        Panel2.setLayout(Panel2Layout);
        Panel2Layout.setHorizontalGroup(
            Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel2Layout.createSequentialGroup()
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelID1)
                            .addComponent(labelPath, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pathChoice, 0, 215, Short.MAX_VALUE)
                            .addComponent(txtID1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnAdd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnRemove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Panel2Layout.createSequentialGroup()
                        .addComponent(btnSavePanel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelPanel2)
                        .addGap(115, 115, 115))))
        );
        Panel2Layout.setVerticalGroup(
            Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelID1)
                    .addComponent(txtID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel2Layout.createSequentialGroup()
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnRemove)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(8, 8, 8)
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pathChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnAdd))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addGroup(Panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnSavePanel2)
                            .addComponent(btnCancelPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(labelPath))
                .addContainerGap())
        );

        Panel1.setName("Panel1"); // NOI18N

        labelID.setText(resourceMap.getString("labelID.text")); // NOI18N
        labelID.setName("labelID"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        txtLonDeg.setText(resourceMap.getString("txtLonDeg.text")); // NOI18N
        txtLonDeg.setName("txtLonDeg"); // NOI18N

        txtLatDeg.setText(resourceMap.getString("txtLatDeg.text")); // NOI18N
        txtLatDeg.setName("txtLatDeg"); // NOI18N

        txtLatMin.setText(resourceMap.getString("txtLatMin.text")); // NOI18N
        txtLatMin.setName("txtLatMin"); // NOI18N

        txtLonMin.setText(resourceMap.getString("txtLonMin.text")); // NOI18N
        txtLonMin.setName("txtLonMin"); // NOI18N

        txtLonSec.setText(resourceMap.getString("txtLonSec.text")); // NOI18N
        txtLonSec.setName("txtLonSec"); // NOI18N

        txtLatSec.setText(resourceMap.getString("txtLatSec.text")); // NOI18N
        txtLatSec.setName("txtLatSec"); // NOI18N

        spinLatitude.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "N", "S" }));
        spinLatitude.setName("spinLatitude"); // NOI18N

        spinLongitude.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "W", "E" }));
        spinLongitude.setName("spinLongitude"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        btnSavePanel1.setText(resourceMap.getString("btnSavePanel1.text")); // NOI18N
        btnSavePanel1.setName("btnSavePanel1"); // NOI18N
        btnSavePanel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSavePanel1ActionPerformed(evt);
            }
        });

        btnCancelPanel1.setText(resourceMap.getString("btnCancelPanel1.text")); // NOI18N
        btnCancelPanel1.setName("btnCancelPanel1"); // NOI18N
        btnCancelPanel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelPanel1ActionPerformed(evt);
            }
        });

        txtID.setText(resourceMap.getString("txtID.text")); // NOI18N
        txtID.setName("txtID"); // NOI18N

        javax.swing.GroupLayout Panel1Layout = new javax.swing.GroupLayout(Panel1);
        Panel1.setLayout(Panel1Layout);
        Panel1Layout.setHorizontalGroup(
            Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(labelID)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel1Layout.createSequentialGroup()
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtLatDeg, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLonDeg, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtLatMin, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLonMin, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Panel1Layout.createSequentialGroup()
                                .addComponent(btnSavePanel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelPanel1))
                            .addGroup(Panel1Layout.createSequentialGroup()
                                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(Panel1Layout.createSequentialGroup()
                                        .addComponent(txtLatSec, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel10))
                                    .addGroup(Panel1Layout.createSequentialGroup()
                                        .addComponent(txtLonSec, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(spinLatitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(spinLongitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        Panel1Layout.setVerticalGroup(
            Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelID))
                .addGap(18, 18, 18)
                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel1Layout.createSequentialGroup()
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLatDeg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel11))
                        .addGap(26, 26, 26)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLonDeg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(txtLonMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(txtLatMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(Panel1Layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtLonSec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)))
                    .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtLatSec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel10))
                    .addGroup(Panel1Layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(spinLongitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(spinLatitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSavePanel1)
                    .addComponent(btnCancelPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 466, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 17, Short.MAX_VALUE)
                    .addComponent(Panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 17, Short.MAX_VALUE)))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 26, Short.MAX_VALUE)
                    .addComponent(Panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 26, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 195, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 3, Short.MAX_VALUE)
                    .addComponent(Panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 4, Short.MAX_VALUE)))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 9, Short.MAX_VALUE)
                    .addComponent(Panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 9, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSavePanel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSavePanel1ActionPerformed
        Vector< String > errorMsg = validateInput();

        if (errorMsg != null && errorMsg.size()>0)
        {
            StringBuffer messageBuffer = new StringBuffer();
            Iterator messages = errorMsg.iterator();

            while (messages.hasNext()) {
                messageBuffer.append((String) messages.next());
                messageBuffer.append("      " + System.getProperty("line.separator"));
            }

            JOptionPane.showMessageDialog(this, messageBuffer.toString(),
                    "Input Data Error", JOptionPane.ERROR_MESSAGE);

            return;
        }

        switch (this.table_id)
        {
            case databaseSettings.AIRPORTS:
            {
                String lat_sign = (String)spinLatitude.getItemAt(spinLatitude.getSelectedIndex());
                String lon_sign = (String)spinLongitude.getItemAt(spinLongitude.getSelectedIndex());
                if (isEdit)
                {
                    db.createUpdateQuery("UPDATE airports SET Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign
                            + "' WHERE ID_Airports = '" + ID + "';");
                }
                else
                {   
                    db.createUpdateQuery("INSERT INTO airports SET "
                            + "ID_Airports = '" + txtID.getText()
                            + "', Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign + "';");
                }
                this.dbset.updateTable(databaseSettings.AIRPORTS, this.isEdit, getIsi());
                break;
            }
            case databaseSettings.FIXES:
            {
                String lat_sign = (String)spinLatitude.getItemAt(spinLatitude.getSelectedIndex());
                String lon_sign = (String)spinLongitude.getItemAt(spinLongitude.getSelectedIndex());
                if (isEdit)
                {
                    db.createUpdateQuery("UPDATE fixes SET Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign
                            + "' WHERE ID_Fixes = '" + ID + "';");
                }
                else
                {
                    db.createUpdateQuery("INSERT INTO fixes SET "
                            + "ID_Fixes = '" + txtID.getText()
                            + "', Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign + "';");
                }
                this.dbset.updateTable(databaseSettings.FIXES, this.isEdit, getIsi());
                break;
            }
            case databaseSettings.NAVAIDS:
            {
                String lat_sign = (String)spinLatitude.getItemAt(spinLatitude.getSelectedIndex());
                String lon_sign = (String)spinLongitude.getItemAt(spinLongitude.getSelectedIndex());
                if (isEdit)
                {
                    db.createUpdateQuery("UPDATE navaids SET Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign
                            + "' WHERE ID_Navaids = '" + ID + "';");
                }
                else
                {
                    db.createUpdateQuery("INSERT INTO navaids SET "
                            + "ID_Navaids = '" + txtID.getText()
                            + "', Lat_Deg = '" + txtLatDeg.getText()
                            + "', Lat_Min = '" + txtLatMin.getText()
                            + "', Lat_Sec = '" + txtLatSec.getText()
                            + "', Lat_Sign = '" + lat_sign
                            + "', Lon_Deg = '" + txtLonDeg.getText()
                            + "', Lon_Min = '" + txtLonMin.getText()
                            + "', Lon_Sec = '" + txtLonSec.getText()
                            + "', Lon_Sign = '" + lon_sign + "';");
                }
                this.dbset.updateTable(databaseSettings.NAVAIDS, this.isEdit, getIsi());
                break;
            }
            default:
                break;
        }
        dispose();
    }//GEN-LAST:event_btnSavePanel1ActionPerformed

    private void btnCancelPanel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelPanel1ActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelPanel1ActionPerformed

    private void btnSavePanel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSavePanel2ActionPerformed
        Vector< String > errorMsg = validateInput();

        if (errorMsg != null && errorMsg.size()>0)
        {
            StringBuffer messageBuffer = new StringBuffer();
            Iterator messages = errorMsg.iterator();

            while (messages.hasNext()) {
                messageBuffer.append((String) messages.next());
                messageBuffer.append("      " + System.getProperty("line.separator"));
            }

            JOptionPane.showMessageDialog(this, messageBuffer.toString(),
                    "Input Data Error", JOptionPane.ERROR_MESSAGE);

            return;
        }

        switch (this.table_id)
        {
            case databaseSettings.AIRWAYS:
            {
                if (isEdit)
                {
                    db.createUpdateQuery("UPDATE airways SET Path_Airways = '" + getIsi()[1]
                            + "' WHERE ID_Airways = '" + ID + "';");
                }
                else
                {
                    db.createUpdateQuery("INSERT INTO airways SET "
                            + "ID_Airways = '" + txtID1.getText()
                            + "', Path_Airways = '" + getIsi()[1] + "';");
                }
                this.dbset.updateTable(databaseSettings.AIRWAYS, this.isEdit, getIsi());
                break;
            }
            case databaseSettings.FLIGHT_PLAN:
            {
                if (isEdit)
                {
                    db.createUpdateQuery("UPDATE flightplan SET Path_FlightPlan = '" + getIsi()[1]
                            + "' WHERE ID_Flight = '" + ID + "';");
                }
                else
                {
                    db.createUpdateQuery("INSERT INTO flightplan SET "
                            + "ID_Flight = '" + txtID1.getText()
                            + "', Path_FlightPlan = '" + getIsi()[1] + "';");
                }
                this.dbset.updateTable(databaseSettings.FLIGHT_PLAN, this.isEdit, getIsi());
                break;
            }
        }
        dispose();
    }//GEN-LAST:event_btnSavePanel2ActionPerformed

    private void btnCancelPanel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelPanel2ActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelPanel2ActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        if (pathList.getSelectedIndex() != -1)
        {
            pathChoice.addItem(listModel.getElementAt(pathList.getSelectedIndex()));
            listModel.removeElementAt(pathList.getSelectedIndex());
        }
    }//GEN-LAST:event_btnRemoveActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        if (pathChoice.getSelectedIndex() != -1)
        {
            listModel.addElement(pathChoice.getSelectedItem());
            pathChoice.removeItemAt(pathChoice.getSelectedIndex());
        }
    }//GEN-LAST:event_btnAddActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Panel1;
    private javax.swing.JPanel Panel2;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancelPanel1;
    private javax.swing.JButton btnCancelPanel2;
    private javax.swing.JButton btnRemove;
    private javax.swing.JButton btnSavePanel1;
    private javax.swing.JButton btnSavePanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelID;
    private javax.swing.JLabel labelID1;
    private javax.swing.JLabel labelPath;
    private javax.swing.JComboBox pathChoice;
    private javax.swing.JList pathList;
    private javax.swing.JComboBox spinLatitude;
    private javax.swing.JComboBox spinLongitude;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtID1;
    private javax.swing.JTextField txtLatDeg;
    private javax.swing.JTextField txtLatMin;
    private javax.swing.JTextField txtLatSec;
    private javax.swing.JTextField txtLonDeg;
    private javax.swing.JTextField txtLonMin;
    private javax.swing.JTextField txtLonSec;
    // End of variables declaration//GEN-END:variables

}
